var btnenable="true";
mui.init({
	swipeBack:false, //启用右滑关闭功能
	keyEventBind: {
		backbutton: false  //关闭back按键监听
	}
}); 
//入口
mui.plusReady(initSomething);
function initSomething(){
	$("#backdiv").height(document.body.scrollHeight);
	var username = plus.storage.getItem("username");
	var password = plus.storage.getItem("password");
	if(username&&password){
		//自动登陆
		dologin(username,password);
	}
}
      
//登录按钮事件
var login_click=function (){
	var username=eval(document.getElementById('username')).value;
    var password=eval(document.getElementById('password')).value;
    if(btnenable=="true"){
        btnenable="false";
		dologin(username,password);
    }else{
   	  	mui.toast('您点的太快了啊，休息下再点吧。');
    }
}

function dologin(username,password){
	mui.ajax(ctx+'mobile/login/doLogin',{
				data:{
						username:username,
						password:password
					},
		        dataType:'json',
		        type:'post',
		        timeout:10000,
		        success:function(data){
		        	btnenable="true";
			       	if(data && data.success){
			       		plus.storage.setItem("username",username);
			   	     	plus.storage.setItem("userid",username);
			   	     	plus.storage.setItem("orgid",data.data.org.id);
			   	     	plus.storage.setItem("orgtype",data.data.org.type);
			   	     	plus.storage.setItem("orgname",data.data.org.name);
			   	     	plus.storage.setItem("password",password);
						mui.openWindow({url: 'index.html',id:'index.html',createNew:true,waiting:{autoShow:false}});
			      	}else{
			      		alert(data.message);
			      		mui.toast(data.message);
			      	}
		      	},
		      	error:function(xhr,type,errorThrown){
		      		btnenable="true";
			     	alert('服务器异常链接失败!');
		      	}
		});
}
